package com.anjufang.controller.system;

import com.anjufang.controller.BaseController;
import com.anjufang.entity.SourceHouse;
import com.anjufang.entity.SourceUser;
import com.anjufang.service.system.SourceDataHouseService;
import com.anjufang.utils.Result;
import com.anjufang.utils.StringUtils;
import com.anjufang.utils.TokenManager;
import com.anjufang.utils.page.PageUtils;
import com.anjufang.utils.page.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sys/sourceHouse/")
public class SourceDataHouseController extends BaseController {
    @Autowired
    private SourceDataHouseService sourceHouseService;

    /**
     * 房源分页
     */
    @RequestMapping(value = LIST)
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        Query query = new Query(params);
        List<SourceHouse> houseList = sourceHouseService.queryList(query);
        int total = sourceHouseService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(houseList, total, query.getLimit(), query.getPage());

        return pageUtil;
    }

    /**
     * 删除
     */
    @RequestMapping(value = DELETE)
    public Result delete(Long id) {
        SourceHouse sourceHouse = new SourceHouse();
        sourceHouse.setId(id);
        sourceHouse.setIsDeleted(1);
        sourceHouse.updateById();
        return Result.ok();
    }

    /**
     * 查剩余房源数
     * parme
     */
    @RequestMapping("count")
    public Result delete(Integer type) {
        int sourceHouseNum = 0;
        if(StringUtils.isBlank(type)){
            sourceHouseNum = new SourceHouse().selectCount("status = 0 and is_deleted = {0}",0);
        }else{
            sourceHouseNum = new SourceHouse().selectCount("type = {0} and status = 0 and is_deleted = {1}",type, 0);
        }
        return Result.ok().put("sourceHouseNum",sourceHouseNum);
    }

}
